package com.xm.servlet.background.commodity;

import com.google.gson.Gson;

import com.xm.service.background.CommodityService;
import lombok.SneakyThrows;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 根据商品id查询
 *
 * @author 吴
 * @date 2024年1月8日
 */
@WebServlet("/background/commodity/by/id")
public class GetCommodityByIdServlet extends HttpServlet {
    private final CommodityService commodityService = new CommodityService();

    @SneakyThrows
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        resp.setContentType("text/html;charset=UTF-8");
        String commodityId = req.getParameter("commodityId");
        resp.getWriter().println(new Gson().toJson(commodityService.getCommodityById(Integer.parseInt(commodityId))));
    }
}
